package wsz.code.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import wsz.code.service.AuthCodeService;
import wsz.util.CommonResult;

/**
 * @author wsz
 * @date 2021/12/27 11:25
 **/
@RestController
@RequestMapping(value = "code")
public class ServiceCodeController {

    @Autowired
    private AuthCodeService codeEmailService;

    @GetMapping(value = "create/{email}")
    public boolean create(@PathVariable(name = "email") String email) {
        return codeEmailService.create(email);
    }

    /**
     * 校验code
     * @param email
     * @param code
     * @return
     */
    @GetMapping(value = "validate/{email}/{code}")
    public CommonResult validate(@PathVariable(name = "email") String email, @PathVariable(name = "code") String code) {
        return CommonResult.getDefault(codeEmailService.validate(email, code));
    }
}
